﻿@model Models.DataModel.Country

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Add new country</h2>

@using (Html.BeginForm("Create","Country",FormMethod.Post)) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true)
       @if (@ViewBag.Check != null)
       {
           <span style="color:red;">@ViewBag.Check</span>
       }
       
        <div class="form-group">
        <div class="form-group">
            @Html.LabelFor(model => model.Code, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Code)
                @Html.ValidationMessageFor(model => model.Code)
                <em class="error" id="codeer" style="display:none; color:red;" >Please input your code Country</em>
                
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
                <em class="error" id="nameer" style="display:none; color:red;">Please input your name Country</em>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input id="BtnSave" type="submit" value="Create" class="btn btn-primary" />
            </div>
        </div>
    </div>
  </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
    $('#BtnSave').click(function () {
        var Code = $("#Code").val().trim();
        var Name = $("#Name").val().trim();
        if (Code == "") {
            $("#codeer").css("display", "block");
            return false;
        } 
        if (Name == "") {
            $("#nameer").css("display", "block");
            return false;
        }
    });
</script>